/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.service.impl;

import cc.altius.dao.CenterDao;
import cc.altius.dao.CustomerDao;
import cc.altius.dao.DoctorDao;
import cc.altius.dao.EmailDao;
import cc.altius.model.Customer;
import cc.altius.model.EmailTemplate;
import cc.altius.model.HealthSpringCenter;
import cc.altius.service.EmailService;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.mail.Address;
import javax.mail.MessagingException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.jasypt.util.numeric.BasicIntegerNumberEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import org.springframework.stereotype.Service;

/**
 *
 * @author mudassar
 */
@Service("emailService")
public class EmailServiceImpl implements EmailService {

    @Autowired
    private EmailDao emailDao;
    @Autowired
    private JavaMailSenderImpl javaMailSend;
    @Autowired
    private CenterDao centerDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private CustomerDao customerDao;
    @Autowired
    private BasicIntegerNumberEncryptor basicIntegerNumberEncryptor;

    @Override
    public List<EmailTemplate> getEmailTemplates() {
        return this.emailDao.getEmailTemplates();
    }

    @Override
    public String createEmailBody(String customerName,int customerId, int emailTemplateId, int centerId, String centerName,String centerContact ,int doctorId, String doctorName, String appointmentDate, String agentName, String mrNo, String phone1, String address, String cheifComplaint, String serviceName, String hospitalName) {
        switch (emailTemplateId) {
            case 1:
                String emailBody1 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                        + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                        + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                        + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                        + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                        + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear <b>" + customerName + "</b>, </td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Hope you are doing well.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> As per your request an appointment with <b>" + doctorName + " </b> has been set in <b>" + centerName + "("+centerContact+")</b> on <b>" + appointmentDate + "</b>.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> We look forward to interacting with you.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Warm Regards,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>Healthspring</b> </td> </tr>"
                        + "</table></td></tr>";

                return emailBody1;
            case 2:
                String emailBody2 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                        + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                        + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                        + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                        + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                        + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear Team ,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">We have fixed an appointment for <b>" + customerName + "</b> with <b>" + doctorName + "</b> on <b>" + appointmentDate + "</b>.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Regards,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>" + agentName + "</b> </td> </tr>"
                        + "</table></td></tr>";

                return emailBody2;
            case 3:
                BigInteger customerId1 = this.basicIntegerNumberEncryptor.encrypt(new BigInteger(String.valueOf(customerId)));
                //String url2 = "http://server3.altius.cc:8080/HealthSpring/customer/onlineRegistrationForm.htm?customerId="+customerId1;
                String url = " https://www.surveymonkey.com/s/Healthspring_Tele-consultation_Feedback";
               //String url="http://localhost:8084/HealthSpring/customer/onlineRegistrationForm.htm?customerId="+customerId1;
                
                String emailBody3 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                        + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                        + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                        + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                        + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                        + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear <b>" + customerName + "</b>, </td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Thank you for calling us - we hope we were able to take care of you!</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">We would love to hear what you thought of the experience. Please could you fill out a short feedback form  <a href="+url+"> here </a> </td> </tr>"
//                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
//                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"><b>( <a href="+url+"> Click here to access the feedback form </a> )</b></td> </tr>"
                         + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">It just takes 1 minute, and helps us do our job better.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Warm Regards,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>Healthspring</b></td> </tr>"
                        + "</table></td></tr>";

                return emailBody3;
            case 4:
                String emailBody4 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                        + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                        + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                        + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                        + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                        + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear <b>" + doctorName + "</b>, </td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">The name of the patient is: " + customerName + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">MR.No: " + mrNo + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Phone: " + phone1 + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Address/Location: " + address + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Regards,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>" + agentName + "</b> </td> </tr>"
                        + "</table></td></tr>";

                return emailBody4;
            case 5:
                String emailBody5 = null;
                HealthSpringCenter healthSpringCenter = this.centerDao.getCenterById(centerId);
                if (healthSpringCenter != null) {
                    emailBody5 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                            + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                            + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                            + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                            + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                            + "</td> </tr>"
                            + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear <b>" + customerName + "</b>, </td> </tr>"
                            + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Hope you are doing well.</td> </tr>"
                            + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> As per your request, kindly find the address and phone number of <b>" + centerName + "</b> mentioned below:</td> </tr>"
                            + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Centre address: " + healthSpringCenter.getAddress() + " & phone number: " + healthSpringCenter.getPhoneNumber() + "</td> </tr>"
                            + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\">We look forward to interacting with you.</td> </tr>"
                            + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Warm Regards,</td> </tr>"
                            + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>Healthspring</b> </td> </tr>"
                            + "</table></td></tr>";
                    return emailBody5;
                } else {
                    emailBody5 = "";
                    return emailBody5;
                }

            case 6:
                String emailBody6 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                        + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                        + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                        + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                        + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                        + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear <b>" + customerName + "</b>, </td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Hope you are doing well.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Kindly find the requested information mentioned below:</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> " + serviceName + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">We look forward to interacting with you.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Warm Regards,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>Healthspring</b> </td> </tr>"
                        + "</table></td></tr>";

                return emailBody6;
            case 7:
                //FOR GETTING YESTERDAYS DATE
                String yesterDayDate;
                //Date curDate = DateUtils.getCurrentDateObject(DateUtils.IST);
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                Calendar calReturn = Calendar.getInstance();
                calReturn.add(Calendar.DATE, -1);
                Date startDate1 = calReturn.getTime();
                yesterDayDate = dateFormat.format(startDate1);
                System.out.println("yesterDayDate :" + yesterDayDate);

                List<Map<String, Object>> customerList = this.customerDao.getListOfTeleConsult(yesterDayDate);
                System.out.println("customerList :" + customerList);
                String emailBody7 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                        + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                        + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                        + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                        + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                        + " </td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear Dr.  <b>" + doctorName + "</b>, </td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Hope you are doing well.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Mentioned below are patients/ customers who availed a tele-consult yesterday:</td> </tr>";
                int number = 1;
                for (Map<String, Object> customerItem : customerList) {


                    emailBody7 += " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                            + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> " + number + ". Customer Name : " + customerItem.get("customerName") + " & Phone No.-" + customerItem.get("phone1") + "</td> </tr>";
                    number++;
                }

                emailBody7 += " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">Warm Regards,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>" + agentName + "</b> </td> </tr>"
                        + "</table></td></tr>";

                return emailBody7;
            case 8:
                String emailBody8 = "<head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> <title>Dear Center head name,</title> "
                        + " <style type='text/css'>  body { 	margin-left: 0px;	margin-top: 0px;	margin-right: 0px;	margin-bottom: 0px;}</style></head>"
                        + " <body>  <table width=\"800\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">  "
                        + "  <tr>    <td colspan=\"2\" bgcolor=\"#FFFFFF\" valign=\"top\">  <table width=\"800\" border=\"0\" cellspacing=\"0\" "
                        + " cellpadding=\"0\">      <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> "
                        + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">  Dear Team , </td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\">We just attended an ICICI Emergency.</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Patient name: " + customerName + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Phone no: " + phone1 + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Chief Complaint: " + cheifComplaint + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Address/Location: " + address + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Hospital Name: " + hospitalName + "</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> Regards,</td> </tr>"
                        + " <tr>       <td colspan=\"2\" width=\"444\" bgcolor=\"#FFFFFF\" style=\"color:#4f3330;"
                        + "  font-family:'arial'; font-size:13px; padding-left:41px;\"> <b>" + agentName + "</b> </td> </tr>"
                        + "</table></td></tr>";

                return emailBody8;
        }
        return null;
    }

    @Override
    public void sendEmail(String emailBody, Customer customer, int emailTemplateId, int doctorId, int centerId) {
        int successCount = 0;
        int failedCount = 0;
        String emailId = null;
        String subject = null;
        String reason = null;
        switch (emailTemplateId) {
            case 1:
                emailId = customer.getEmailId();
                subject = "Healthspring Appointment Confirmation";
                break;
            case 2:
                emailId = this.centerDao.getEmailIdOfCentre(centerId);
                subject = "Appointment for " + customer.getCustomerName() + "";
                break;
            case 3:
                emailId = customer.getEmailId();
                subject = "Tele-consultation Feedback";
                break;
            case 4:
                emailId = this.doctorDao.getEmailIdOfDoctor(doctorId);
                subject = "Tele-consultation Patient Details";
                break;
            case 5:
                emailId = customer.getEmailId();
                subject = "Healthspring Community Medical Centre";
                break;
            case 6:
                emailId = customer.getEmailId();
                subject = "Service Details";
                break;
            case 7:
                emailId = this.doctorDao.getEmailIdOfDoctor(doctorId);
                subject = "Tele-consultation Follow-up reminder";
                break;
            case 8:
                emailId = "emergencyresponse_team@healthspring.in";
                subject = "Emergency Attended";
                break;
        }

        try {
            Address addressFrom;
            MimeMessage msg = this.javaMailSend.createMimeMessage();
            addressFrom = new InternetAddress("icici@healthspring.in", "HEALTHSPRING");
            msg.setFrom(addressFrom);
            msg.setRecipients(MimeMessage.RecipientType.TO, (String) emailId);
            msg.setSubject(subject);
            //String url = "http://server3.altius.cc:8080/HealthSpring/customer/addCustomer.htm";
            String url = "http://localhost:8084/HealthSpring/customer/addCustomer.htm";
//            StringBuilder params = new StringBuilder("?emailId=").append(eml.getVerificationEmailId()).append("&token=").append(eml.getToken());
//            StringBuilder sb = new StringBuilder("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title>XRBIA</title>");
//            sb.append("<style>.general {font-family: sans-serif;font-size: 14px;font-weight: normal;margin-left: 20px;} .img {margin-left: 5px;}</style></head>");
//            sb.append("<body>");
//            sb.append("<p class=\"general\">Dear ").append(customer.getName()).append(",</p>");
//            sb.append("<p class=\"general\">Greetings from the Republic of Xrbia.</p>");
//            sb.append("<p class=\"general\">You are requested to confirm your details via our verification process. It is sometimes possible, due to the inconsistent or incorrect data we have received at the time of data collection, that some information may be incorrect. We request you to kindly make the necessary changes so we can safely proceed to the registration process.</p>");
//            sb.append("<p class=\"general\">Please follow the link to verify your details: <br/><a href=\"").append(url).append(params).append("\">").append(url).append(params).append("</a></p>");
//            sb.append("<p class=\"general\">Best regards,<br/>Xrbia</p>");
//            sb.append("<p class=\"img\"><img src=\"%3D%3D\"/></p>");
//            sb.append("</body></html>");
            msg.setContent(emailBody, "text/html");
            this.javaMailSend.send(msg);

            successCount++;
            reason = "Success";
            this.emailDao.addEmail(customer.getCustomerId(), emailId, emailBody, emailTemplateId, successCount, reason, subject);
        } catch (MessagingException ex) {
            failedCount++;
            reason = ex.toString();
            this.emailDao.addEmail(customer.getCustomerId(), emailId, emailBody, emailTemplateId, 2, reason, subject);
            ex.printStackTrace();
        } catch (UnsupportedEncodingException ex) {
            failedCount++;
            this.emailDao.addEmail(customer.getCustomerId(), emailId, emailBody, emailTemplateId, 2, reason, subject);
            ex.printStackTrace();
        } catch (Exception ex) {
            failedCount++;
            this.emailDao.addEmail(customer.getCustomerId(), emailId, emailBody, emailTemplateId, 2, reason, subject);
            ex.printStackTrace();
        }

        //this.emailDao.addEmail(customer.getCustomerId(), emailId, emailBody, emailTemplateId,failedCount,reason);
    }
}
